﻿// JSON C# Class Generator
// http://at-my-window.blogspot.com/?page=json-class-generator

using System;
using Newtonsoft.Json.Linq;
using BuscoPre;
using BuscoPre.Repository.MLA.JsonTypes;

namespace BuscoPre.Repository.MLA
{

    public class SearchResult
    {

        public SearchResult(string json)
         : this(JObject.Parse(json))
        {
        }

        private JObject __jobject;
        public SearchResult(JObject obj)
        {
            this.__jobject = obj;
        }

        public string SiteId
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "site_id"));
            }
        }

        public string Query
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "query"));
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private Paging _paging;
        public Paging Paging
        {
            get
            {
                if(_paging == null)
                    _paging = JsonClassHelper.ReadStronglyTypedObject<Paging>(JsonClassHelper.GetJToken<JObject>(__jobject, "paging"));
                return _paging;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private Result[] _results;
        public Result[] Results
        {
            get
            {
                if(_results == null)
                    _results = (Result[])JsonClassHelper.ReadArray<Result>(JsonClassHelper.GetJToken<JArray>(__jobject, "results"), JsonClassHelper.ReadStronglyTypedObject<Result>, typeof(Result[]));
                return _results;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private MatchingCatalogProduct[] _matchingCatalogProducts;
        public MatchingCatalogProduct[] MatchingCatalogProducts
        {
            get
            {
                if(_matchingCatalogProducts == null)
                    _matchingCatalogProducts = (MatchingCatalogProduct[])JsonClassHelper.ReadArray<MatchingCatalogProduct>(JsonClassHelper.GetJToken<JArray>(__jobject, "matching_catalog_products"), JsonClassHelper.ReadStronglyTypedObject<MatchingCatalogProduct>, typeof(MatchingCatalogProduct[]));
                return _matchingCatalogProducts;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private Sort _sort;
        public Sort Sort
        {
            get
            {
                if(_sort == null)
                    _sort = JsonClassHelper.ReadStronglyTypedObject<Sort>(JsonClassHelper.GetJToken<JObject>(__jobject, "sort"));
                return _sort;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private AvailableSort[] _availableSorts;
        public AvailableSort[] AvailableSorts
        {
            get
            {
                if(_availableSorts == null)
                    _availableSorts = (AvailableSort[])JsonClassHelper.ReadArray<AvailableSort>(JsonClassHelper.GetJToken<JArray>(__jobject, "available_sorts"), JsonClassHelper.ReadStronglyTypedObject<AvailableSort>, typeof(AvailableSort[]));
                return _availableSorts;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private Filter[] _filters;
        public Filter[] Filters
        {
            get
            {
                if(_filters == null)
                    _filters = (Filter[])JsonClassHelper.ReadArray<Filter>(JsonClassHelper.GetJToken<JArray>(__jobject, "filters"), JsonClassHelper.ReadStronglyTypedObject<Filter>, typeof(Filter[]));
                return _filters;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private AvailableFilter[] _availableFilters;
        public AvailableFilter[] AvailableFilters
        {
            get
            {
                if(_availableFilters == null)
                    _availableFilters = (AvailableFilter[])JsonClassHelper.ReadArray<AvailableFilter>(JsonClassHelper.GetJToken<JArray>(__jobject, "available_filters"), JsonClassHelper.ReadStronglyTypedObject<AvailableFilter>, typeof(AvailableFilter[]));
                return _availableFilters;
            }
        }

    }
}
